package com.project.app.system;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.domain.entity.SysUserWx;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.system.service.ISysUserWxService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 微信用户信息Controller
 *
 * @author project
 * @date 2021-08-25
 */
@RestController
@RequestMapping("/app/system/userWx")
public class SysUserWxController extends BaseController {

    @Resource
    private ISysUserWxService userWxService;

/**
 * 查询微信用户信息列表
 */
//@PreAuthorize("@ss.hasPermi('server:info:list')")
@GetMapping("/list")
        public TableDataInfo list(SysUserWx userWx) {
        startPage();
        List<SysUserWx> list = userWxService.selectSysUserWxList(userWx);
        return getDataTable(list);
    }

    
    /**
     * 导出微信用户信息列表
     */
   // @PreAuthorize("@ss.hasPermi('server:info:export')")
    @Log(title = "微信用户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysUserWx userWx) {
        List<SysUserWx> list = userWxService.selectSysUserWxList(userWx);
        ExcelUtil<SysUserWx> util = new ExcelUtil<SysUserWx>(SysUserWx. class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取微信用户信息详细信息
     */
    //@PreAuthorize("@ss.hasPermi('server:info:query')")
    @GetMapping(value = "/{wechatId}")
    public AjaxResult getInfo(@PathVariable("wechatId") Long wechatId) {
        return AjaxResult.success(userWxService.selectSysUserWxById(wechatId));
    }

    /**
     * 新增微信用户信息
     */
    //@PreAuthorize("@ss.hasPermi('server:info:add')")
    @Log(title = "微信用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysUserWx userWx) {
        return toAjax(userWxService.insertSysUserWx(userWx));
    }

    /**
     * 认证微信用户信息
     */
    //@PreAuthorize("@ss.hasPermi('server:info:edit')")
    @Log(title = "微信用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysUserWx userWx) {
        return toAjax(userWxService.updateSysUserWx(userWx));
    }

    /**
     * 删除微信用户信息
     */
   // @PreAuthorize("@ss.hasPermi('server:info:remove')")
    @Log(title = "微信用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wechatIds}")
    public AjaxResult remove(@PathVariable Long[] wechatIds) {
        return toAjax(userWxService.deleteSysUserWxByIds(wechatIds));
    }
}
